const Router = require('koa-router')

const router = new Router({ prefix: '/questions/:questionId/answers' })

const auth = require('../middleware/auth')
const { checkAnswerExist } = require('../middleware/exist')
const { checkAnswerer } = require('../middleware/check')

const {
  find,
  findById,
  create,
  update,
  delete: del
} = require('../controllers/answers')

// 获取（整体）
router.get('/', find)

// 获取（单一）
router.get('/:id', findById)

// 新增
router.post('/', auth, create)

// 更新
router.patch('/:id', auth, checkAnswerExist, checkAnswerer, update)

// 删除
router.delete('/:id', auth, checkAnswerExist, checkAnswerer, del)

module.exports = router
